import instacne from "../request";
import type { Ref } from 'vue'
import qs from 'qs'
/**
/flashProductRelation/create
 * 
 */
interface IFlashProductData {
    flashPromotionCount?: number | Ref<number>
    flashPromotionId?: number | Ref<number>
    flashPromotionLimit?: number | Ref<number>
    flashPromotionPrice?: number | Ref<number>
    flashPromotionSessionId?: number | Ref<number>
    id?: number | Ref<number>
    productId?: number | Ref<number>
    sort?: number | Ref<number>
}
const PFlashProduct = (data: IFlashProductData[]) => {
    return instacne.post(`/flashProductRelation/create`, data)
}


/**
 * flashProductRelation/update/63 
 * /flashProductRelation/update/{id}
修改关联信息
 */
interface iii {
    flashPromotionCount?: number | Ref<number>
    flashPromotionId?: number | Ref<number>
    flashPromotionLimit?: number | Ref<number>
    flashPromotionPrice?: number | Ref<number>
    flashPromotionSessionId?: number | Ref<number>
    id?: number | Ref<number>
    productId?: number | Ref<number>
    sort?: number | Ref<number>
}
interface IUpdataFalseh {
    relation?: iii | any
    product?: any | Ref<any>
}
const UpdataFlashProduct = (data: IUpdataFalseh) => {
    return instacne.post(`flashProductRelation/update/${data.relation.id}`, data)
}

/**
 * /flashProductRelation/delete/{id}
删除关联
 */
const DeleteFlashProduct = (id: number | Ref<number>) => {
    return instacne.post(`/flashProductRelation/delete/${id}`, id)
}


/**
 * /flashSession/update/status/4?status=1  启用
 */
interface IStatus {
    id?: number | Ref<number>
    status?: number | Ref<number>
}
const PUpdatastatus = (data: IStatus) => {
    return instacne.post(`/flashSession/update/status/${data.id}?status=${data.status}`)
}


/**
 * /productCategory/list/withChildren
 * /productCategory/list/withChildren
查询所有一级分类及子分类
 */

interface IWithChildrenres {
    children?: IWithChildrenres | Ref<IWithChildrenres>
    description?: string | Ref<string>
    icon?: string | Ref<string>
    id?: number | Ref<number>
    keywords?: string | Ref<string>
    level?: number | Ref<number>
    name?: string | Ref<string>
    navStatus?: number | Ref<number>
    parentId?: number | Ref<number>
    productCount?: number | Ref<number>
    productUnit?: string | Ref<string>
    showStatus?: number | Ref<number>
    sort?: number | Ref<number>
    value: string | Ref<string>
    labels: string | Ref<string>
}
const GetwithChildren = (): Promise<IWithChildrenres> => {
    return instacne.get(`/productCategory/list/withChildren`)
}

/**
 * /flashProductRelation/list 分页查询不同场次关联及商品信息
 */
interface IProductData {
    pageNum?: number | Ref<number>,
    pageSize?: number | Ref<number>,
    flashPromotionSessionId?: number | Ref<number>,
    flashPromotionId?: number | Ref<number>
}
interface IProductRes {
    list: any[]
    pageNum: number,
    pageSize: number,
    total: number,
    totalPage: number
}
const ProductRelationList = (data: IProductData): Promise<IProductRes> => {
    return instacne.get(`/flashProductRelation/list`, { params: data })
}
/**
 * /flash/list 根据优惠券名称和类型分页获取优惠券列表
 */
interface ICouponData {
    name?: string | Ref<string>
    pageNum?: number | Ref<number>
    pageSize?: number | Ref<number>
    type?: number | Ref<number>
    couponId?: number | Ref<number>
    orderSn?: string | Ref<string>
    keyword?: string | Ref<string>
}
interface ICouponPomis {
    list: any[]
    pageNum: number,
    pageSize: number,
    total: number,
    totalPage: number

}
const getcouponList = (data: ICouponData): Promise<ICouponPomis> => {
    return instacne.get('/flash/list', { params: data })
}
/**
 * /coupon/list  根据优惠券名称和类型分页获取优惠券列表
 */
interface ICouponListdata {

    name?: string | Ref<string>
    pageNum?: number | Ref<number>
    pageSize?: number | Ref<number>
    type?: number | Ref<number>
}
interface ICouponres {
    list: any
    pageNum: number,
    pageSize: number,
    total: number,
    totalPage: number
}
const getCouponListres = (data: ICouponListdata): Promise<ICouponres> => {
    return instacne.get('/coupon/list', { params: data })
}
/**
 * /coupon/delete/{id} 删除优惠券
 */
const deleteCoupon = (id: number | Ref<number>) => {
    return instacne.post(`/coupon/delete/${id}`)
}
/**
 * /flash/create 添加活动
 */
interface IFlashUpdate {
    createTime?: string | Ref<string>,
    endDate?: string | Ref<string>,
    id?: number | Ref<number>,
    startDate?: string | Ref<string>,
    status?: number | Ref<number>,
    title?: string | Ref<string>,
    name?: string | Ref<string>
}
const CFlashCreate = (data: IFlashUpdate) => {
    return instacne.post(`/flash/create`, data)
}
/**
 * /flashSession/create 添加场次
 */

interface ICreateSession {
    createTime?: string | Ref<string>,
    endTime?: string | Ref<string>,
    id?: number | Ref<number>,
    name?: string | Ref<string>,
    startTime?: string | Ref<string>,
    status?: number | Ref<number>
}
const CreateSession = (data: ICreateSession) => {
    return instacne.post(`/flashSession/create`, data)
}
/**
 * /flashSession/delete/{id}  删除场次
 */

const DeleteSession = (id: number | Ref<number>) => {
    return instacne.post(`/flashSession/delete/${id}`)
}
/**
 * /product/list?pageNum=1&pageSize=5  /product/list  查询商品
 */
interface IProductListData {
    keyword?: string | Ref<string>
    pageNum?: number | Ref<number>
    pageSize?: number | Ref<number>
    total?: number | Ref<number>
    totalPage?: number | Ref<number>
    productCategoryId?: number | Ref<number>
    brandId?: number | Ref<number>
    publishStatus?: number | Ref<number>
    verifyStatus?: number | Ref<number>
    productSn?: string | Ref<string>
}

const GProductList = (data: IProductListData): Promise<IProductRes> => {
    return instacne.get(`/product/list`, { params: data })
}
/**
 * /flashSession/update/{id}  修改场次
 */

const UpdateSession = (data: ICreateSession) => {
    return instacne.post(`/flashSession/update/${data.id}`, data)
}
/**
 * /flashSession/list   获取全部场次
 */
interface ssssssssss {
    createTime: string,
    endTime: string,
    id: number,
    name: string,
    startTime: string,
    status: number
}
interface IFlashSessList {
    data: ssssssssss[]
    message: string
}
const getFlashSessList = (): Promise<IFlashSessList> => {
    return instacne.get(`/flashSession/list  `)
}
/**
 * /flash/delete/{id} 删除活动
 */
const flashDelete = (id: number) => {
    return instacne.post(`/flash/delete/${id}`)
}
/**
 * /flash/update/{id} 编辑活动
 */
interface IFlashUpdate {
    createTime?: string | Ref<string>,
    endDate?: string | Ref<string>,
    id?: number | Ref<number>,
    startDate?: string | Ref<string>,
    status?: number | Ref<number>,
    title?: string | Ref<string>,
    name?: string | Ref<string>
}
const flashUpdate = (data: IFlashUpdate) => {
    return instacne.post(`/flash/update/${data.id}`, data)
}

/**
 * /flash/update/status/{id} 修改上下线状态
 */
interface IUpdateData {
    status?: number | Ref<number>
    id?: number | Ref<number>

}
const updateStatus = (data: IUpdateData) => {
    return instacne.post(`/flash/update/status/${data.id}?status=${data.status}`, data)
}

/**
 * /flashSession/selectList  获取全部可选场次及其数量
 */

const selectListSession = (flashPromotionId?: number | Ref<number>) => {
    return instacne.get(`/flashSession/selectList?flashPromotionId=${flashPromotionId}`)
}

/**
 * /home/brand/list 分页查询推荐品牌
 */
interface IHomeBranddata {
    brandName?: string | Ref<string>
    pageNum?: number | Ref<number>
    pageSize?: number | Ref<number>
    recommendStatus?: number | Ref<number>
}
interface IHomeBrandRes {
    list: any[]
    pageNum: number,
    pageSize: number,
    total: number,
    totalPage: number
}
const getHomeList = (data: IHomeBranddata): Promise<IHomeBrandRes> => {
    return instacne.get('/home/brand/list', { params: data })
}
/**
 * /product/simpleList?keyword=1 
 * /product/simpleList
根据商品名称或货号模糊查询
 */
interface ProductSimpleData {
    keyword?: string | Ref<string>
}
const getProductSimpleList = (data: ProductSimpleData): Promise<any[]> => {
    return instacne.get(`/product/simpleList`, { params: data })
}
/**
 * /product/update/publishStatus 批量上下架
 */
interface UPpublish {
    ids: number | number[] | Ref<number> | Ref<number[]>
    publishStatus: number
}
const uppublishStatus = (data: UPpublish) => {
    return instacne.post(`/product/update/publishStatus?ids=${data.ids}&publishStatus=${data.publishStatus}`)
}
/**
 * /product/update/newStatus 批量设为新品
 */
interface UPnewStatus {
    ids: number | number[] | Ref<number[]> | Ref<number>
    newStatus: number
}
const upnewStatus = (data: UPnewStatus) => {
    return instacne.post(`/product/update/newStatus?ids=${data.ids}&newStatus=${data.newStatus}`)
}
/**
 * /product/update/recommendStatus  批量推荐商品
 */
interface IUprecommendStatus {
    ids: number | number[] | Ref<number[]> | Ref<number>
    recommendStatus: number
}
const uprecommendStatus = (data: IUprecommendStatus) => {
    return instacne.post(`/product/update/recommendStatus?ids=${data.ids}&recommendStatus=${data.recommendStatus}`)
}
/**
 * /product/list  查询商品
 */
interface IGoodslistData {
    brandId?: number | Ref<number>
    keyword?: string | Ref<string>
    pageNum?: number | Ref<number>
    pageSize?: number | Ref<number>
    productCategoryId?: number | Ref<number>
    productSn?: string | Ref<string>
    publishStatus?: number | Ref<number>
    verifyStatus?: number | Ref<number>
}

interface IGoosOlldata {
    pageNum: number,
    pageSize: number,
    total: number,
    totalPage: number,
    list: any[]
}

const getGoodsList = (data: IGoodslistData): Promise<IGoosOlldata> => {
    return instacne.get('/product/list', { params: data })
}
/**
 * /coupon/create
添加优惠券
 */
interface IRelationList {
    couponId?: number | Ref<number>,
    id?: number | Ref<number>,
    parentCategoryName?: string | Ref<string>,
    productCategoryId?: number | Ref<number>,
    productCategoryName?: string | Ref<string>
}
interface IRelation {
    couponId?: number | Ref<number>,
    id?: number | Ref<number>,
    productId?: number | Ref<number>,
    productName?: string | Ref<string>,
    productSn?: string | Ref<string>
}
interface ICouponCreateData {
    amount?: number | Ref<number>
    code?: string,
    count?: number | Ref<number>
    enableTime?: string | Ref<string>
    endTime?: string | Ref<string>
    id?: number | Ref<number>
    memberLevel?: number | Ref<number>
    minPoint?: number | Ref<number>
    name?: string | Ref<string>
    note?: string | Ref<string>
    perLimit?: number | Ref<number>
    platform?: number | Ref<number>
    productCategoryRelationList?: IRelationList[] | Ref<IRelationList[]> | undefined
    productRelationList?: IRelation[] | Ref<IRelation[]> | undefined
    publishCount?: number | Ref<number>
    receiveCount?: number | Ref<number>
    startTime?: string | Ref<string>
    type?: number | Ref<number>
    useCount?: number | Ref<number>
    useType?: number | Ref<number>
}
const postcouponCreate = (data: ICouponCreateData): Promise<any> => {
    return instacne.post(`/coupon/create`, data)
}
/**
 * /coupon/{id}
获取单个优惠券的详细信息
 */
interface IGetCoupon {
    id?: number | Ref<number>
}
const GetCoupon = (data: IGetCoupon): Promise<ICouponCreateData> => {
    return instacne.get(`/coupon/${data.id}`)
}
/**
 * /couponHistory/list
根据优惠券id，使用状态，订单编号分页获取领取记录
 */

const GetCouponHistoryList = (data: ICouponData): Promise<ICouponPomis> => {
    return instacne.get(`/couponHistory/list`, { params: data })
}

/**
 * /coupon/update/25
 * /coupon/update/{id}
修改优惠券
 */
// interface IUpdata {
//     couponParam?: ICouponCreateData
// }
const PostUpdataCoupon = (data: ICouponCreateData) => {
    return instacne.post(`/coupon/update/${data.id}`, data)
}

/**
 * /product/update/deleteStatus?ids=1344&deleteStatus=1
 * /product/update/deleteStatus
批量修改删除状态
 */
interface IUpdataDeleteStatus {
    ids?: number[] | Ref<number[]> | number | Ref<number>
    deleteStatus?: number | Ref<number>
}
const POStproductupdata = (data: IUpdataDeleteStatus) => {
    return instacne.post(`/product/update/deleteStatus?ids=${data.ids}&deleteStatus=1`)
}



// /home/brand/list
// 分页查询推荐品牌
interface newProductRes {
    pageNum?: number
    pageSize?: number
    productName?: string
    recommendStatus?: number
}
interface newProductlist {
    id: number,
    brandId: number,
    brandName: string,
    recommendStatus: number,
    sort: number
}
interface newProductPms {
    list: newProductlist[],
    pageNum: number,
    pageSize: number,
    total: number,
    totalPage: number
}
const getnewProduc = (data: newProductRes): Promise<newProductPms> => {
    return instacne.get('/home/brand/list', { params: data })
}
// /home/brand/delete
// 批量删除推荐品牌
const deletenewproductlist = (iaaa: string) => {
    return instacne.post('/home/brand/delete', qs.stringify({ ids: iaaa }))
}

interface upnewproductRes {
    ids: string,
    recommendStatus: number,

}
// /home/brand/update/recommendStatus
// 批量修改推荐品牌状态
const upnewproductlist = (data: upnewproductRes) => {
    return instacne.post('/home/brand/update/recommendStatus', qs.stringify({
        ids: data.ids,
        recommendStatus: data.recommendStatus
    }))

}
interface upsortRes {
    id: number,
    sort: number
}
// /home/brand/update/sort/{id}
// 修改推荐品牌排序
const upsort = (data: upsortRes) => {
    return instacne.post(`/home/brand/update/sort/${data.id}`, qs.stringify(data))
}
interface createproductRes {
    brandId: number,
    brandName: string
}
// /home/brand/create
// 添加首页推荐品牌
const createproductlist = (data: createproductRes) => {
    return instacne.post('/home/brand/create', data)
}

// /brand/list
// 查询商品
interface InquireRes {
    keyword?: string
    pageNum?: number
    pageSize?: number
}
const Inquiresp = (data: InquireRes): Promise<any> => {
    return instacne.get('/brand/list', {
        params: data
    })
}
export {
    Inquiresp,
    createproductlist,
    upsort,
    upnewproductlist,
    deletenewproductlist,
    getnewProduc,
    POStproductupdata,
    PostUpdataCoupon,
    GetCouponHistoryList,
    GetCoupon,
    postcouponCreate,
    getGoodsList,
    uprecommendStatus,
    upnewStatus,
    uppublishStatus,
    getProductSimpleList,
    getHomeList,
    selectListSession,
    updateStatus,
    flashUpdate,
    flashDelete,
    getFlashSessList,
    UpdateSession,
    GProductList,
    PFlashProduct,
    UpdataFlashProduct,
    DeleteFlashProduct,
    PUpdatastatus,
    GetwithChildren,
    ProductRelationList,
    getCouponListres,
    deleteCoupon,
    getcouponList,
    CFlashCreate,
    CreateSession,
    DeleteSession,
}
export type {
    IWithChildrenres, IGoosOlldata, ICouponCreateData
}